<script setup lang="ts">
import { ref } from 'vue'
import { useUserStore } from '@/store/modules/user'
import { useRouter } from 'vue-router'
import { ElNotification } from 'element-plus'

const router = useRouter()
const userStore = useUserStore()
const userInfo = ref({
  username: 'LinLin',
  password: '123456',
})
const loginBtn = async () => {
  await userStore.getLogin(userInfo.value)
  if (userStore.UserInfo.token) {
    ElNotification({
      title: '登录成功',
      message: '欢迎回来',
      type: 'success',
    })
    router.push('/')
  } else {
    ElNotification({
      title: '登录失败',
      message: '请检查用户名密码',
      type: 'error',
    })
  }
}
</script>

<template>
  <div class="box">
    <el-card>
      <el-form label-width="80px">
        <el-form-item label="用户名">
          <el-input placeholder="请输入用户名" v-model="userInfo.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" show-password placeholder="请输入密码" v-model="userInfo.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="loginBtn">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<style lang="scss" scoped>
.box {
  width: 100vw;
  height: 100vh;
  background-color: #d0d0d0;
  .el-card {
    max-width: 1200px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>
